package com.peanut.wapp.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.peanut.wapp.controller.resBean.RNewsBean;
import com.peanut.wapp.service.NewsService;

@Controller
@RequestMapping("/page")
public class PageController {
	
	@Autowired
	NewsService newsServiceImpl;

	@RequestMapping("/index")
	public ModelAndView toIndex() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("index");

		return mv;
	}

	@RequestMapping("/detail")
	public ModelAndView toDetail() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("detail");

		return mv;
	}

	@RequestMapping("/about")
	public ModelAndView toAbout() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("about-us");

		return mv;
	}

	@RequestMapping("/info")
	public ModelAndView toInfo() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("info");

		return mv;
	}
	
	@RequestMapping("/value")
	public ModelAndView toValue() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("value");

		return mv;
	}

	@RequestMapping("/info/detail")
	public ModelAndView toInfoDetail(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView();
		String nid = request.getParameter("nid");
		if(nid != null) {
			
			RNewsBean news = newsServiceImpl.getDetail(nid);
			mv.addObject("news", news);
		}
		mv.setViewName("info-detail");

		return mv;
	}
	
}